import torch

from refiners.conversion.utils import Conversion, Hub, WeightRecipe

diffusers_recipe = WeightRecipe(
    key_map={
        "encoder.conv_in": "Encoder.Conv2d",
        "encoder.down_blocks.0.resnets.0.norm1": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_1",
        "encoder.down_blocks.0.resnets.0.norm2": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_2",
        "encoder.down_blocks.0.resnets.1.norm1": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_1",
        "encoder.down_blocks.0.resnets.1.norm2": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_2",
        "encoder.down_blocks.1.resnets.0.norm1": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_1",
        "decoder.up_blocks.3.resnets.0.norm2": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_2",
        "decoder.up_blocks.3.resnets.1.norm1": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_1",
        "decoder.up_blocks.3.resnets.1.norm2": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_2",
        "decoder.up_blocks.3.resnets.2.norm1": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.GroupNorm_1",
        "decoder.up_blocks.3.resnets.2.norm2": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.GroupNorm_2",
        "decoder.conv_norm_out": "Decoder.Chain_2.GroupNorm",
        "encoder.down_blocks.0.resnets.0.conv1": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_1",
        "encoder.down_blocks.0.resnets.0.conv2": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_2",
        "encoder.down_blocks.0.resnets.1.conv1": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_1",
        "encoder.down_blocks.0.resnets.1.conv2": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_2",
        "encoder.down_blocks.0.downsamplers.0.conv": "Encoder.Chain_1.Chain_1.Downsample.Conv2d",
        "decoder.up_blocks.3.resnets.0.conv2": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_2",
        "decoder.up_blocks.3.resnets.1.conv1": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_1",
        "decoder.up_blocks.3.resnets.1.conv2": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_2",
        "decoder.up_blocks.3.resnets.2.conv1": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.Conv2d_1",
        "decoder.up_blocks.3.resnets.2.conv2": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.Conv2d_2",
        "encoder.down_blocks.1.resnets.0.conv1": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_1",
        "encoder.down_blocks.1.resnets.0.norm2": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_2",
        "encoder.down_blocks.1.resnets.1.norm1": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_1",
        "encoder.down_blocks.1.resnets.1.norm2": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_2",
        "encoder.down_blocks.2.resnets.0.norm1": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_1",
        "decoder.up_blocks.2.resnets.0.norm2": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_2",
        "decoder.up_blocks.2.resnets.1.norm1": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_1",
        "decoder.up_blocks.2.resnets.1.norm2": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_2",
        "decoder.up_blocks.2.resnets.2.norm1": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.GroupNorm_1",
        "decoder.up_blocks.2.resnets.2.norm2": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.GroupNorm_2",
        "decoder.up_blocks.3.resnets.0.norm1": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_1",
        "encoder.down_blocks.1.resnets.0.conv2": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_2",
        "encoder.down_blocks.1.resnets.1.conv1": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_1",
        "encoder.down_blocks.1.resnets.1.conv2": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_2",
        "encoder.down_blocks.1.downsamplers.0.conv": "Encoder.Chain_1.Chain_2.Downsample.Conv2d",
        "decoder.up_blocks.2.resnets.0.conv2": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_2",
        "decoder.up_blocks.2.resnets.1.conv1": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_1",
        "decoder.up_blocks.2.resnets.1.conv2": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_2",
        "decoder.up_blocks.2.resnets.2.conv1": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.Conv2d_1",
        "decoder.up_blocks.2.resnets.2.conv2": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.Conv2d_2",
        "decoder.up_blocks.2.upsamplers.0.conv": "Decoder.Chain_1.Chain_4.Upsample.Conv2d",
        "encoder.down_blocks.1.resnets.0.conv_shortcut": "Encoder.Chain_1.Chain_2.Resnet_1.Conv2d",
        "encoder.down_blocks.2.resnets.0.conv1": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_1",
        "encoder.down_blocks.2.resnets.0.norm2": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_2",
        "encoder.down_blocks.2.resnets.1.norm1": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_1",
        "encoder.down_blocks.2.resnets.1.norm2": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_2",
        "encoder.down_blocks.3.resnets.0.norm1": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_1",
        "encoder.down_blocks.3.resnets.0.norm2": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_2",
        "encoder.down_blocks.3.resnets.1.norm1": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_1",
        "encoder.down_blocks.3.resnets.1.norm2": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_2",
        "encoder.mid_block.resnets.0.norm1": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_1",
        "encoder.mid_block.resnets.0.norm2": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_2",
        "encoder.mid_block.attentions.0.group_norm": "Encoder.Chain_1.Chain_5.Residual.GroupNorm",
        "encoder.mid_block.resnets.1.norm1": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_1",
        "encoder.mid_block.resnets.1.norm2": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_2",
        "encoder.conv_norm_out": "Encoder.Chain_2.GroupNorm",
        "decoder.mid_block.resnets.0.norm1": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_1",
        "decoder.mid_block.resnets.0.norm2": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_2",
        "decoder.mid_block.attentions.0.group_norm": "Decoder.Chain_1.Chain_1.Residual.GroupNorm",
        "decoder.mid_block.resnets.1.norm1": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_1",
        "decoder.mid_block.resnets.1.norm2": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_2",
        "decoder.up_blocks.0.resnets.0.norm1": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_1",
        "decoder.up_blocks.0.resnets.0.norm2": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_2",
        "decoder.up_blocks.0.resnets.1.norm1": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_1",
        "decoder.up_blocks.0.resnets.1.norm2": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_2",
        "decoder.up_blocks.0.resnets.2.norm1": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.GroupNorm_1",
        "decoder.up_blocks.0.resnets.2.norm2": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.GroupNorm_2",
        "decoder.up_blocks.1.resnets.0.norm1": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_1",
        "decoder.up_blocks.1.resnets.0.norm2": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_2",
        "decoder.up_blocks.1.resnets.1.norm1": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_1",
        "decoder.up_blocks.1.resnets.1.norm2": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_2",
        "decoder.up_blocks.1.resnets.2.norm1": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.GroupNorm_1",
        "decoder.up_blocks.1.resnets.2.norm2": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.GroupNorm_2",
        "decoder.up_blocks.2.resnets.0.norm1": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_1",
        "encoder.down_blocks.2.resnets.0.conv2": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_2",
        "encoder.down_blocks.2.resnets.1.conv1": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_1",
        "encoder.down_blocks.2.resnets.1.conv2": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_2",
        "encoder.down_blocks.2.downsamplers.0.conv": "Encoder.Chain_1.Chain_3.Downsample.Conv2d",
        "encoder.down_blocks.3.resnets.0.conv1": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_1",
        "encoder.down_blocks.3.resnets.0.conv2": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_2",
        "encoder.down_blocks.3.resnets.1.conv1": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_1",
        "encoder.down_blocks.3.resnets.1.conv2": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_2",
        "encoder.mid_block.resnets.0.conv1": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_1",
        "encoder.mid_block.resnets.0.conv2": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_2",
        "encoder.mid_block.resnets.1.conv1": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_1",
        "encoder.mid_block.resnets.1.conv2": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_2",
        "decoder.mid_block.resnets.0.conv1": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_1",
        "decoder.mid_block.resnets.0.conv2": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_2",
        "decoder.mid_block.resnets.1.conv1": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_1",
        "decoder.mid_block.resnets.1.conv2": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_2",
        "decoder.up_blocks.0.resnets.0.conv1": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_1",
        "decoder.up_blocks.0.resnets.0.conv2": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_2",
        "decoder.up_blocks.0.resnets.1.conv1": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_1",
        "decoder.up_blocks.0.resnets.1.conv2": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_2",
        "decoder.up_blocks.0.resnets.2.conv1": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.Conv2d_1",
        "decoder.up_blocks.0.resnets.2.conv2": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.Conv2d_2",
        "decoder.up_blocks.0.upsamplers.0.conv": "Decoder.Chain_1.Chain_2.Upsample.Conv2d",
        "decoder.up_blocks.1.resnets.0.conv1": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_1",
        "decoder.up_blocks.1.resnets.0.conv2": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_2",
        "decoder.up_blocks.1.resnets.1.conv1": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_1",
        "decoder.up_blocks.1.resnets.1.conv2": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_2",
        "decoder.up_blocks.1.resnets.2.conv1": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.Conv2d_1",
        "decoder.up_blocks.1.resnets.2.conv2": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.Conv2d_2",
        "decoder.up_blocks.1.upsamplers.0.conv": "Decoder.Chain_1.Chain_3.Upsample.Conv2d",
        "encoder.down_blocks.2.resnets.0.conv_shortcut": "Encoder.Chain_1.Chain_3.Resnet_1.Conv2d",
        "encoder.mid_block.attentions.0.to_q": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_1",
        "encoder.mid_block.attentions.0.to_k": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_2",
        "encoder.mid_block.attentions.0.to_v": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_3",
        "encoder.mid_block.attentions.0.to_out.0": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Linear",
        "decoder.mid_block.attentions.0.to_q": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_1",
        "decoder.mid_block.attentions.0.to_k": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_2",
        "decoder.mid_block.attentions.0.to_v": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_3",
        "decoder.mid_block.attentions.0.to_out.0": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Linear",
        "encoder.conv_out": "Encoder.Chain_2.Conv2d",
        "quant_conv": "Encoder.Chain_3.Conv2d",
        "post_quant_conv": "Decoder.Conv2d_1",
        "decoder.conv_in": "Decoder.Conv2d_2",
        "decoder.up_blocks.2.resnets.0.conv1": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_1",
        "decoder.up_blocks.2.resnets.0.conv_shortcut": "Decoder.Chain_1.Chain_4.Resnet_1.Conv2d",
        "decoder.up_blocks.3.resnets.0.conv1": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_1",
        "decoder.up_blocks.3.resnets.0.conv_shortcut": "Decoder.Chain_1.Chain_5.Resnet_1.Conv2d",
        "decoder.conv_out": "Decoder.Chain_2.Conv2d",
    },
    key_aliases={
        "encoder.mid_block.attentions.0.value": "encoder.mid_block.attentions.0.to_v",
        "decoder.mid_block.attentions.0.value": "decoder.mid_block.attentions.0.to_v",
        "decoder.mid_block.attentions.0.proj_attn": "decoder.mid_block.attentions.0.to_out.0",
        "encoder.mid_block.attentions.0.proj_attn": "encoder.mid_block.attentions.0.to_out.0",
        "encoder.mid_block.attentions.0.key": "encoder.mid_block.attentions.0.to_k",
        "decoder.mid_block.attentions.0.key": "decoder.mid_block.attentions.0.to_k",
        "decoder.mid_block.attentions.0.query": "decoder.mid_block.attentions.0.to_q",
        "encoder.mid_block.attentions.0.query": "encoder.mid_block.attentions.0.to_q",
    },
)

civitai_recipe = WeightRecipe(
    key_prefix="first_stage_model.",
    key_map={
        "encoder.conv_in": "Encoder.Conv2d",
        "encoder.down.0.block.0.norm1": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_1",
        "encoder.down.0.block.0.conv1": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_1",
        "encoder.down.0.block.0.norm2": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_2",
        "encoder.down.0.block.0.conv2": "Encoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_2",
        "encoder.down.0.block.1.norm1": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_1",
        "encoder.down.0.block.1.conv1": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_1",
        "encoder.down.0.block.1.norm2": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_2",
        "encoder.down.0.block.1.conv2": "Encoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_2",
        "encoder.down.0.downsample.conv": "Encoder.Chain_1.Chain_1.Downsample.Conv2d",
        "encoder.down.1.block.0.norm1": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_1",
        "encoder.down.1.block.0.conv1": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_1",
        "encoder.down.1.block.0.norm2": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_2",
        "encoder.down.1.block.0.conv2": "Encoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_2",
        "encoder.down.1.block.0.nin_shortcut": "Encoder.Chain_1.Chain_2.Resnet_1.Conv2d",
        "encoder.down.1.block.1.norm1": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_1",
        "encoder.down.1.block.1.conv1": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_1",
        "encoder.down.1.block.1.norm2": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_2",
        "encoder.down.1.block.1.conv2": "Encoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_2",
        "encoder.down.1.downsample.conv": "Encoder.Chain_1.Chain_2.Downsample.Conv2d",
        "encoder.down.2.block.0.norm1": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_1",
        "encoder.down.2.block.0.conv1": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_1",
        "encoder.down.2.block.0.norm2": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_2",
        "encoder.down.2.block.0.conv2": "Encoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_2",
        "encoder.down.2.block.0.nin_shortcut": "Encoder.Chain_1.Chain_3.Resnet_1.Conv2d",
        "encoder.down.2.block.1.norm1": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_1",
        "encoder.down.2.block.1.conv1": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_1",
        "encoder.down.2.block.1.norm2": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_2",
        "encoder.down.2.block.1.conv2": "Encoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_2",
        "encoder.down.2.downsample.conv": "Encoder.Chain_1.Chain_3.Downsample.Conv2d",
        "encoder.down.3.block.0.norm1": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_1",
        "encoder.down.3.block.0.conv1": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_1",
        "encoder.down.3.block.0.norm2": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_2",
        "encoder.down.3.block.0.conv2": "Encoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_2",
        "encoder.down.3.block.1.norm1": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_1",
        "encoder.down.3.block.1.conv1": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_1",
        "encoder.down.3.block.1.norm2": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_2",
        "encoder.down.3.block.1.conv2": "Encoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_2",
        "encoder.mid.block_1.norm1": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_1",
        "encoder.mid.block_1.conv1": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_1",
        "encoder.mid.block_1.norm2": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_2",
        "encoder.mid.block_1.conv2": "Encoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_2",
        "encoder.mid.attn_1.norm": "Encoder.Chain_1.Chain_5.Residual.GroupNorm",
        "encoder.mid.attn_1.q": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_1",
        "encoder.mid.attn_1.k": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_2",
        "encoder.mid.attn_1.v": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_3",
        "encoder.mid.attn_1.proj_out": "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Linear",
        "encoder.mid.block_2.norm1": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_1",
        "encoder.mid.block_2.conv1": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_1",
        "encoder.mid.block_2.norm2": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_2",
        "encoder.mid.block_2.conv2": "Encoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_2",
        "encoder.norm_out": "Encoder.Chain_2.GroupNorm",
        "encoder.conv_out": "Encoder.Chain_2.Conv2d",
        "quant_conv": "Encoder.Chain_3.Conv2d",
        "post_quant_conv": "Decoder.Conv2d_1",
        "decoder.conv_in": "Decoder.Conv2d_2",
        "decoder.mid.block_1.norm1": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_1",
        "decoder.mid.block_1.conv1": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_1",
        "decoder.mid.block_1.norm2": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.GroupNorm_2",
        "decoder.mid.block_1.conv2": "Decoder.Chain_1.Chain_1.Resnet_1.Chain.Conv2d_2",
        "decoder.mid.attn_1.norm": "Decoder.Chain_1.Chain_1.Residual.GroupNorm",
        "decoder.mid.attn_1.q": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_1",
        "decoder.mid.attn_1.k": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_2",
        "decoder.mid.attn_1.v": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_3",
        "decoder.mid.attn_1.proj_out": "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Linear",
        "decoder.mid.block_2.norm1": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_1",
        "decoder.mid.block_2.conv1": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_1",
        "decoder.mid.block_2.norm2": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.GroupNorm_2",
        "decoder.mid.block_2.conv2": "Decoder.Chain_1.Chain_1.Resnet_2.Chain.Conv2d_2",
        "decoder.up.3.block.0.norm1": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_1",
        "decoder.up.3.block.0.conv1": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_1",
        "decoder.up.3.block.0.norm2": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.GroupNorm_2",
        "decoder.up.3.block.0.conv2": "Decoder.Chain_1.Chain_2.Resnet_1.Chain.Conv2d_2",
        "decoder.up.3.block.1.norm1": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_1",
        "decoder.up.3.block.1.conv1": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_1",
        "decoder.up.3.block.1.norm2": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.GroupNorm_2",
        "decoder.up.3.block.1.conv2": "Decoder.Chain_1.Chain_2.Resnet_2.Chain.Conv2d_2",
        "decoder.up.3.block.2.norm1": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.GroupNorm_1",
        "decoder.up.3.block.2.conv1": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.Conv2d_1",
        "decoder.up.3.block.2.norm2": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.GroupNorm_2",
        "decoder.up.3.block.2.conv2": "Decoder.Chain_1.Chain_2.Resnet_3.Chain.Conv2d_2",
        "decoder.up.3.upsample.conv": "Decoder.Chain_1.Chain_2.Upsample.Conv2d",
        "decoder.up.2.block.0.norm1": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_1",
        "decoder.up.2.block.0.conv1": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_1",
        "decoder.up.2.block.0.norm2": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.GroupNorm_2",
        "decoder.up.2.block.0.conv2": "Decoder.Chain_1.Chain_3.Resnet_1.Chain.Conv2d_2",
        "decoder.up.2.block.1.norm1": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_1",
        "decoder.up.2.block.1.conv1": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_1",
        "decoder.up.2.block.1.norm2": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.GroupNorm_2",
        "decoder.up.2.block.1.conv2": "Decoder.Chain_1.Chain_3.Resnet_2.Chain.Conv2d_2",
        "decoder.up.2.block.2.norm1": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.GroupNorm_1",
        "decoder.up.2.block.2.conv1": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.Conv2d_1",
        "decoder.up.2.block.2.norm2": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.GroupNorm_2",
        "decoder.up.2.block.2.conv2": "Decoder.Chain_1.Chain_3.Resnet_3.Chain.Conv2d_2",
        "decoder.up.2.upsample.conv": "Decoder.Chain_1.Chain_3.Upsample.Conv2d",
        "decoder.up.1.block.0.norm1": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_1",
        "decoder.up.1.block.0.conv1": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_1",
        "decoder.up.1.block.0.norm2": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.GroupNorm_2",
        "decoder.up.1.block.0.conv2": "Decoder.Chain_1.Chain_4.Resnet_1.Chain.Conv2d_2",
        "decoder.up.1.block.0.nin_shortcut": "Decoder.Chain_1.Chain_4.Resnet_1.Conv2d",
        "decoder.up.1.block.1.norm1": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_1",
        "decoder.up.1.block.1.conv1": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_1",
        "decoder.up.1.block.1.norm2": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.GroupNorm_2",
        "decoder.up.1.block.1.conv2": "Decoder.Chain_1.Chain_4.Resnet_2.Chain.Conv2d_2",
        "decoder.up.1.block.2.norm1": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.GroupNorm_1",
        "decoder.up.1.block.2.conv1": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.Conv2d_1",
        "decoder.up.1.block.2.norm2": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.GroupNorm_2",
        "decoder.up.1.block.2.conv2": "Decoder.Chain_1.Chain_4.Resnet_3.Chain.Conv2d_2",
        "decoder.up.1.upsample.conv": "Decoder.Chain_1.Chain_4.Upsample.Conv2d",
        "decoder.up.0.block.0.norm1": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_1",
        "decoder.up.0.block.0.conv1": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_1",
        "decoder.up.0.block.0.norm2": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.GroupNorm_2",
        "decoder.up.0.block.0.conv2": "Decoder.Chain_1.Chain_5.Resnet_1.Chain.Conv2d_2",
        "decoder.up.0.block.0.nin_shortcut": "Decoder.Chain_1.Chain_5.Resnet_1.Conv2d",
        "decoder.up.0.block.1.norm1": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_1",
        "decoder.up.0.block.1.conv1": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_1",
        "decoder.up.0.block.1.norm2": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.GroupNorm_2",
        "decoder.up.0.block.1.conv2": "Decoder.Chain_1.Chain_5.Resnet_2.Chain.Conv2d_2",
        "decoder.up.0.block.2.norm1": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.GroupNorm_1",
        "decoder.up.0.block.2.conv1": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.Conv2d_1",
        "decoder.up.0.block.2.norm2": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.GroupNorm_2",
        "decoder.up.0.block.2.conv2": "Decoder.Chain_1.Chain_5.Resnet_3.Chain.Conv2d_2",
        "decoder.norm_out": "Decoder.Chain_2.GroupNorm",
        "decoder.conv_out": "Decoder.Chain_2.Conv2d",
    },
    tensor_reshapes={
        "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_1.weight": (512, 512),
        "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_2.weight": (512, 512),
        "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Distribute.Linear_3.weight": (512, 512),
        "Encoder.Chain_1.Chain_5.Residual.SelfAttention2d.Linear.weight": (512, 512),
        "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_1.weight": (512, 512),
        "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_2.weight": (512, 512),
        "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Distribute.Linear_3.weight": (512, 512),
        "Decoder.Chain_1.Chain_1.Residual.SelfAttention2d.Linear.weight": (512, 512),
    },
)


runwayml = Conversion(
    original=Hub(
        repo_id="stable-diffusion-v1-5/stable-diffusion-v1-5",
        filename="vae/diffusion_pytorch_model.safetensors",
        revision="f03de327dd89b501a01da37fc5240cf4fdba85a1",
        expected_sha256="a2b5134f4dbc140d9c11f11cba3233099e00af40f262f136c691fb7d38d2194c",
    ),
    converted=Hub(
        repo_id="refiners/sd15.autoencoder",
        filename="model.safetensors",
        expected_sha256="3f499ef1c668a8dfc72762d885f53cf0c3d3e98a393211906a8de5ae04e72058",
    ),
    recipe=diffusers_recipe,
    dtype=torch.float32,
)
stability_mse = Conversion(
    original=Hub(
        repo_id="stabilityai/sd-vae-ft-mse",
        filename="diffusion_pytorch_model.safetensors",
        revision="31f26fdeee1355a5c34592e401dd41e45d25a493",
        expected_sha256="a1d993488569e928462932c8c38a0760b874d166399b14414135bd9c42df5815",
    ),
    converted=Hub(
        repo_id="refiners/sd15.autoencoder_mse",
        filename="model.safetensors",
        expected_sha256="4b484e70be3b898e2647985f066495672162a4e9ea1d1ee8bf1f7a7895180fce",
    ),
    recipe=diffusers_recipe,
    dtype=torch.float16,
)
juggernaut_reborn = Conversion(
    original=Hub(
        repo_id="civitai/KandooAi/juggernaut",
        filename="reborn/onefile_fp16.safetensors",
        download_url="https://civitai.com/api/download/models/274039?type=Model&format=SafeTensor&size=pruned&fp=fp16",
        expected_sha256="338b85bc4f7628bc42cce336242e79154a57c2a4360531436e97f7793568f18c",
    ),
    converted=Hub(
        repo_id="refiners/sd15.juggernaut.reborn.autoencoder",
        filename="model.safetensors",
        expected_sha256="6f1ed875201344031f2a9ddee3ff40f455eb2a5ee4833070061a5d163cb23595",
    ),
    recipe=civitai_recipe,
    dtype=torch.float16,
)
juggernaut_aftermath = Conversion(
    original=Hub(
        repo_id="civitai/KandooAi/juggernaut",
        filename="aftermath/onefile_fp32.safetensors",
        download_url="https://civitai.com/api/download/models/127207?type=Model&format=SafeTensor&size=full&fp=fp32",
        expected_sha256="7ed60a2f5842de8e6755965ffbf2a0ee273429939f307233c22f7dffd8d7ae3d",
    ),
    converted=Hub(
        repo_id="refiners/sd15.juggernaut.aftermath.autoencoder",
        filename="model.safetensors",
        expected_sha256="83d147dd0d25231e49ba35820f7dd7f0902ba6e93237d00b6caee0599f010618",
    ),
    recipe=civitai_recipe,
    dtype=torch.float16,
)
# autoencoder wise, juggernaut_aftermath = juggernaut_aftermath_inpainting
realistic_stock_photo_v3 = Conversion(
    original=Hub(
        repo_id="Yntec/realisticStockPhoto3",
        filename="realisticStockPhoto_v30SD15.safetensors",
        expected_sha256="f85affae9aae16276eaf670f810946e2d03c4d300791a0380f07653cb78ba31b",
        # download_url="https://civitai.com/api/download/models/524032?type=Model&format=SafeTensor&size=full&fp=fp16",
    ),
    converted=Hub(
        repo_id="refiners/sd15.realistic_stock_photo.v3_0.autoencoder",
        filename="model.safetensors",
        expected_sha256="4b484e70be3b898e2647985f066495672162a4e9ea1d1ee8bf1f7a7895180fce",
    ),
    recipe=civitai_recipe,
    dtype=torch.float16,
)
realistic_vision_v5 = Conversion(
    original=Hub(
        repo_id="civitai/SG_161222/realistic_vision",
        filename="v5/onefile_fp32.safetensors",
        download_url="https://civitai.com/api/download/models/130072?type=Model&format=SafeTensor&size=full&fp=fp16",
        expected_sha256="ef76aa2332635f4352463343beec9c5aae3bd107a73c0fd7221abbbcf8bd5470",
    ),
    converted=Hub(
        repo_id="refiners/sd15.realistic_vision.v5_1.autoencoder",
        filename="model.safetensors",
        expected_sha256="4b484e70be3b898e2647985f066495672162a4e9ea1d1ee8bf1f7a7895180fce",
    ),
    recipe=civitai_recipe,
    dtype=torch.float16,
)
